<title>项目系统</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>应用</cite></a>
        <a><cite>任务</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="LAY-app-project-issue-search">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <select name="type">
                            <option value="">请选择</option>
                            <option value="0">任务</option>
                            <option value="1">需求</option>
                            <option value="2">缺陷</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">负责人</label>
                    <div class="layui-input-block">
                        <input type="text" name="accept" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-order" lay-submit lay-filter="LAY-app-project-issue-search-submit">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
                <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
            </div>
            <table id="LAY-app-project-issue" lay-filter="LAY-app-project-issue"></table>
            <script type="text/html" id="typeTpl">
                {{#  if(d.type == 0){ }}
                <button class="layui-btn layui-btn-normal layui-btn-xs">任务</button>
                {{#  } else if(d.type == 1){ }}
                <button class="layui-btn layui-btn-primary layui-btn-xs">需求</button>
                {{#  } else{ }}
                <button class="layui-btn layui-btn-warm layui-btn-xs">缺陷</button>
                {{#  } }}
            </script>
            <script type="text/html" id="progressTpl">
                <div class="layui-progress layuiadmin-order-progress" lay-filter="progress-" + {{ d.orderid }} +"">
                    <div class="layui-progress-bar layui-bg-blue" lay-percent={{ d.progress }}></div>
                </div>
            </script>
            <script type="text/html" id="buttonTpl">
                {{#  if(d.status == '已处理'){ }}
                <button class="layui-btn layui-btn-normal layui-btn-xs">已处理</button>
                {{#  } else if(d.status == '未分配'){ }}
                <button class="layui-btn layui-btn-primary layui-btn-xs">未分配</button>
                {{#  } else{ }}
                <button class="layui-btn layui-btn-warm layui-btn-xs">处理中</button>
                {{#  } }}
            </script>
            <script type="text/html" id="LAY-app-project-issue-bar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
            </script>
        </div>
    </div>
</div>

<script>
    layui.use('project', layui.factory('project')).use(['admin', 'project', 'table'], function () {
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , form = layui.form
            , table = layui.table;

        form.render(null, 'LAY-app-project-issue-search');

        //监听搜索
        form.on('submit(LAY-app-project-issue-search-submit)', function (data) {
            var field = data.field;

            //执行重载
            table.reload('LAY-app-project-issue', {
                where: field
            });
        });

        var active = {
            batchdel: function () {
                var checkStatus = table.checkStatus('LAY-app-content-list')
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }

                layer.confirm('确定删除吗？', function (index) {

                    //执行 Ajax 后重载
                    /*
                    admin.req({
                      url: 'xxx'
                      //,……
                    });
                    */
                    table.reload('LAY-app-project-issue');
                    layer.msg('已删除');
                });
            },
            add: function () {
                admin.popup({
                    title: '添加任务'
                    , area: ['550px', '550px']
                    , id: 'LAY-app-project-issue-add'
                    , success: function (layero, index) {
                        view(this.id).render('app/project/issueform').done(function () {
                            form.render(null, 'LAY-app-project-issue-form');

                            //监听提交
                            form.on('submit(LAY-app-project-issue-submit)', function (data) {
                                admin.req({
                                    url: layui.setter.host + '/project/'  + layui.router().search.project_id + "/issue"
                                    , data: data.field
                                    , type: "post"
                                    , done: function (res) {
                                        if (res.code === 0) {
                                            layer.msg(res.message, {icon: 6});
                                            table.reload('LAY-app-project-issue'); //数据刷新
                                            layer.close(index); //关闭弹层
                                        } else {
                                            layer.msg(res.message, {icon: 5});
                                        }
                                    }
                                });
                            });
                        });
                    }
                });
            }
        };

        $('.layui-btn.layuiadmin-btn-list').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>